/**
 * tnx.js
 */
import {convert} from 'xmlbuilder2';
import tnxbs from '../../tnxjs/tnxcore/src/tnxbs.js';
import tnxet from '../../tnxjs/tnxet/src/tnxet';
import tnxel from '../../tnxjs/tnxvue3/src/element-plus/tnxel';
import EnumTypes from '@/logic/enums.js';

export const tnx = tnxbs.util.object.assignDeep({}, tnxbs, tnxet, tnxel);

tnx.util.build.isProduction = function () {
    return window.location.protocol === 'file:';
}

tnx.app.getRoot = function () {
    return tnx.util.build.isProduction() ? 'build' : 'src';
}

tnx.app.validator = Object.assign({}, tnx.app.validator, {
    requiredRule: tnx.app.validator.getRule('required', true),
    manualInputRule: tnx.app.validator.getRule('notContainsHtmlChars', true),
    symbolRule: tnx.app.validator.getRule('regex', {
        pattern: '^[a-zA-Z_$][a-zA-Z\\d_$]*$',
        message: '不满足命名规则，必须以英文字母、_、$开头，且只能包含英文字母、数字、_、$',
    }),
});

tnx.util.xml.parse = function (xml) {
    return convert(xml, {format: 'object'});
}

EnumTypes.forEach(EnumType => EnumType.init(tnx));

window.tnx = tnx;

tnx.util.file.loadSeparator();

export default tnx;
